<template>
  <div class="custom-modal-wrap"
       v-if="isShow">
    <div class="custom-modal"
         :style="{ width }">
      <div class="custom-modal-content">
        <div class="custom-modal-header">
          <div class="title">{{ title }}</div>
          <div class="modal-close"
               @click="handleCancel">
            关闭 <span>ESC</span>
          </div>
        </div>
        <div class="custom-modal-body">
          <div class="alarm-info">
            <slot></slot>
          </div>
        </div>

        <div class="custom-modal-footer"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Modal",
  props: {
    type: {
      type: String,
      default: "confirm"
    },
    title: {
      type: String,
      default: "提示"
    }
  },
  data () {
    return {
      //调用的时候里面的配置除了content外其他都为非必填，不传以默认项为准
      isShow: false, //控制显隐
      content: "", //内容
      okText: "确定",
      cancelText: "取消",
      width: "70%", //百分比或者字符串
    };
  },

  methods: {
    info () {
      this.isShow = true;
    },
    handleConfirm () {
      this.isShow = false;
      if (this.onOK) {
        this.onOK();
      }

    },
    handleCancel () {
      this.isShow = false;
      if (this.onCancel) {
        this.onCancel();
      }
    },
  },
  mounted () {
    let that = this;
    that.$nextTick(() => {
      document.addEventListener("keyup", function (e) {
        if (e.keyCode == 27) {
          that.isShow = false;
        }
      });
    });
  },
};
</script>

<style lang="scss" scoped>
.custom-modal-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  //   display: flex;
  overflow: auto;
  //   justify-content: center;
  //   align-items: center;
  z-index: 999;
  outline: 0;
  background-color: rgba(55, 55, 55, 0.6);
}
.custom-modal {
  width: auto;
  margin: 0 auto;
  position: relative;
  outline: 0;
  top: 100px;
}
.custom-modal-content {
  position: relative;
  background-color: #fff;
  border: 0;
  border-radius: 6px;
  background-clip: padding-box;
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}
.custom-modal-header {
  border-bottom: none;
  height: auto;
  line-height: normal;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
}
.custom-modal-header {
  .title {
    font-size: 22px;
    color: #111111;
    height: auto;
    line-height: normal;
  }
  .modal-close {
    white-space: nowrap;
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    color: #888888;
    span {
      border: 1px solid #eeeeee;
      padding: 2px 8px;
      border-radius: 4px;
      cursor: pointer;
    }
  }
}
.custom-modal-body {
  padding: 0 16px;
  font-size: 14px;
  line-height: 1.5;
}
.custom-modal-footer {
  border-top: none;
  text-align: center;
  padding: 10px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  button:not(first-child) {
    margin-left: 10px;
  }
}
</style>
